import {observable,action, toJS} from 'mobx';
import {Tools,Bubble} from 'weaver-mobile';
import * as API from '../../api/workflowToFna/toDetailPage';

const getLabel = Tools.getLabel;

export default class ToDetailPageStore {
    /********************************************************/
    @observable loading = false;
    @observable hasRight = false;

    isPdf = false;
    imageId = '';
    documentType = '';
    @observable headeData = [];
    @observable bodyData = [];
    @observable detailsArr = [];
    showAllDetailsArr = [];

    @observable detailsEditList = {};

    //获取发票详情
    setPageEmbile = (value={},copyDetails) =>{
        this.loading = true;
        API.setPageEmbile(value).then( res =>{
            const {status,invoiceDetails} = res;
            if(status == '1'){
                const {imageId,isPdf,headeData,bodyData,documentType = 'png'} = invoiceDetails;
                this.imageId = imageId;
                this.isPdf = isPdf;
                this.documentType = documentType;
                this.headeData = headeData;
                this.bodyData = bodyData;

                this.detailsArr = bodyData[0].details;
                
                this.detailsEditList = res.detailsEditList;
                
                if(copyDetails){
                    let copy =  JSON.parse(JSON.stringify(this.detailsArr));
                    copy.map( (items,index)=>{
                        items.show = true;
                    });
                    
                    this.showAllDetailsArr = copy;
                }
            }else{
                Bubble.error(res.errorInfo)
            }
            this.loading = false;
        })
    }

    //改变详情数据
    setDetailsArr = (value=[]) =>{
        this.detailsArr = value;
    }

    setBodyData = (value) =>{
        this.bodyData[0].details = value;
    }

}